package com.mywang.weitravel.modules.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.mywang.weitravel.R;
import com.mywang.weitravel.base.BaseFragment;
import com.mywang.weitravel.model.HomeListBean;
import com.mywang.weitravel.modules.company.CompanyActivity;
import com.mywang.weitravel.modules.manbushanghai.ShangHaiActivity;
import com.mywang.weitravel.modules.read.ReadChinaActivity;
import com.mywang.weitravel.modules.redlocate.RedLocateActivity;
import com.mywang.weitravel.modules.study.StudyTravelActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import me.jessyan.autosize.internal.CustomAdapt;

/**
 * Created by wangmingyun on 2019/12/5.
 */
public class HomeFragment extends BaseFragment<HomePresenter> implements HomeContract.View, CustomAdapt {

    @BindView(R.id.index_red_look)
    ImageView indexRedLook;
    @BindView(R.id.index_shanghai)
    ImageView indexShanghai;
    @BindView(R.id.index_study)
    ImageView indexStudy;
    @BindView(R.id.index_read_china)
    ImageView indexReadChina;
    @BindView(R.id.index_company)
    ImageView indexCompany;
    private ArrayList<String> arrayList;

    @Override
    protected HomePresenter initPresenter() {
        return new HomePresenter(this);
    }

    @Override
    protected int getFragmentLayoutID() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        arrayList = new ArrayList<>();
        arrayList.add("http://img2.imgtn.bdimg.com/it/u=1447362014,2103397884&fm=200&gp=0.jpg");
        arrayList.add("http://img1.imgtn.bdimg.com/it/u=111342610,3492888501&fm=26&gp=0.jpg");
        arrayList.add("http://imgsrc.baidu.com/imgad/pic/item/77094b36acaf2eddc8c37dc7861001e9390193e9.jpg");
        initBanner();
    }

    @Override
    public void setBook(List<HomeListBean> list) {

    }

    /**
     * 初始化轮播图2
     */
    private void initBanner() {

    }

    @OnClick({R.id.index_red_look, R.id.index_shanghai, R.id.index_study, R.id.index_read_china, R.id.index_company})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.index_red_look:
                Intent intent1 = new Intent(mContext, RedLocateActivity.class);
                mContext.startActivity(intent1);
                break;
            case R.id.index_shanghai:
                Intent intent2 = new Intent(mContext, ShangHaiActivity.class);
                mContext.startActivity(intent2);
                break;
            case R.id.index_study:
                Intent intent3 = new Intent(mContext, StudyTravelActivity.class);
                mContext.startActivity(intent3);
                break;
            case R.id.index_read_china:
                Intent intent4 = new Intent(mContext, ReadChinaActivity.class);
                mContext.startActivity(intent4);
                break;
            case R.id.index_company:
                Intent intent5 = new Intent(mContext, CompanyActivity.class);
                mContext.startActivity(intent5);
                break;
        }
    }

    @Override
    public boolean isBaseOnWidth() {
        return true;
    }

    @Override
    public float getSizeInDp() {
        return 800;
    }

    /**
     * 轮播图2 对应的holder
     */
    public class NetImageHolderView extends Holder<String> {
        private ImageView mImageView;

        //构造器
        public NetImageHolderView(View itemView) {
            super(itemView);
        }

        @Override
        protected void initView(View itemView) {
            //找到对应展示图片的imageview
            mImageView = itemView.findViewById(R.id.iv_banner);
            //设置图片加载模式为铺满，具体请搜索 ImageView.ScaleType.FIT_XY
            mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        }

        @Override
        public void updateUI(String data) {
            //使用glide加载更新图片
            Glide.with(mActivity).load(data).into(mImageView);
        }
    }
}
